<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>谷歌绑定列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
</head>
<body class="body">
<div style="padding: 20px;">
    <!-- 表格 -->
    <div id="dateTable" lay-filter="event"></div>
    <div class="height50"></div>
</div>
<script th:src="@{/js/layui/layui.js}"></script>
<script type="text/javascript" th:inline="javascript">
    // layui方法
    layui.use(['table', 'form'], function () {
        // 操作对象
        var table = layui.table
            , $ = layui.jquery;

        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , height: "full"    //容器高度
            , even: 'true'
            , cols: [[                  //标题栏
                {
                    field: 'username', title: '用户名',  sort: true, align: 'center'
                }
                , {title: '操作', align: 'center', toolbar: '#barOption'} //这里的toolbar值是模板元素的选择器
            ]]
            , id: 'dataCheck'
            , url: [[${basePath}]] + '/verify/queryGoogleQRCode'
            , method: 'get'
            , page: false
            , loading: true
            , done: function (res, curr, count) {
            }
        });

        table.on('tool(event)', function (obj) {
            var data = obj.data;
            if (obj.event === 'reset') {
                // 弹框输入谷歌验证码校验后可以重置
                layer.prompt({
                    formType: 0,
                    value: data.remark,
                    title: '请输入谷歌验证码',
                    area: ['800px', '350px'] //自定义文本域宽高
                }, function (value, index, elem) {
                    if (value == null || value == '') {
                        layer.msg("验证码不能为空", {icon: 6, time: 1500});
                        return;
                    }
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/verify/checkGoogleQRCode",
                        data: {
                            code: value
                        },
                        success: function (res) {
                            if (res.success) {
                                // 重置验证码
                                $.ajax({
                                    type: "post",
                                    url: [[${basePath}]] + "/verify/resetGoogleQRCode",
                                    data: {
                                        userName: data.username
                                    },
                                    success: function (res) {
                                        layer.close(index);
                                        if (res.success) {
                                            layer.msg("重置成功！");
                                        }
                                    }
                                });
                            } else {
                                layer.msg(res.msg, {icon: 2}, 2000);
                            }
                        }
                    });
                });

            }
        });
    });
</script>
<!-- 表格操作按钮集 -->
<script type="text/html" id="barOption">
    <a class="layui-btn layui-bg-green layui-btn-xs" lay-event="reset"><i class="layui-icon layui-icon-refresh"></i>重置</a>
</script>
</body>
</html>